﻿using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;
using GISAzureCore;

namespace GISWebRole
{
    public partial class Upload : System.Web.UI.Page
    {
        CloudStorageAccount _account;
        CloudBlobClient _blobClient;
        internal const int BLOCK_SIZE = 32768;

        protected void Page_Load(object sender, EventArgs e)
        {
            _account =  CloudStorageAccount.Parse( 
                RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));

            try
            {
                _blobClient = _account.CreateCloudBlobClient();
            }
            catch (Exception ex)
            {
                Trace.Write(ex.Message);
            }
        }

        protected void bntUploadClick(object sender, EventArgs e)
        {
            if (this.upldMapFile.HasFile)
            {
                var filename = upldMapFile.FileName;
                CloudBlobContainer container = _blobClient.GetContainerReference(DataConstants.MapContainerBlob);
                CloudBlob blob = container.GetBlobReference(filename);
                blob.UploadFromStream(upldMapFile.FileContent);
                upldMapFile.FileContent.Position = 0; // reset for processing
            }            
        }
    }
}
